﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;




namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        ActiveUp.Net.Mail.Imap4Client imapClient;

        public Form1()
        {
            InitializeComponent();
            //przycisk.MouseHover += (object sender, EventArgs e) =>
            //{
            //    MessageBox.Show(((Button)sender).Text);
            //};

            //MobileProxy.MobileProxySoapClient NetcampMobileProxy = new MobileProxy.MobileProxySoapClient();
            /*

            foreach(MobileProxy.RssItem wpisNaStronieNetcamp in NetcampMobileProxy.GetSpeechesFromNetcampWebsite())
            {
                netcampRss.Text += wpisNaStronieNetcamp.Title+ "\r\n";
                netcampRss.Text += wpisNaStronieNetcamp.Date + "\r\n";
                netcampRss.Text += wpisNaStronieNetcamp.Description + "\r\n\r\n";

            }*/

            watek2.RunWorkerCompleted += watek2_RunWorkerCompleted;
            watek2.DoWork += watek2_DoWork;

            imapClient = new ActiveUp.Net.Mail.Imap4Client();
            
            imapClient.ConnectSsl("outlook.office365.com");
            imapClient.Login("noresponse@netcamp.pl", "0okm!234");
            imapClient.SelectMailbox("inbox");
            
            imapClient.MessageRetrieved += imapClient_MessageRetrieved;

            watek2.RunWorkerAsync();

        }

        void watek2_DoWork(object sender, DoWorkEventArgs e)
        {
            if (imapClient != null && imapClient.IsConnected)
            {
                imapClient.StopIdle();
                imapClient.Disconnect();
            }
            imapClient.StartIdle();

        }

        void watek2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            watek2.RunWorkerAsync();
        }

        void imapClient_MessageRetrieved(object sender, ActiveUp.Net.Mail.MessageRetrievedEventArgs e)
        {

            this.netcampRss.Text = e.Message.BodyText.Text + e.Message.BodyHtml.Text;
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            

            /*
            // Call the method that runs asynchronously.
            //string result = await WaitAsynchronouslyAsync();

            // Call the method that runs synchronously.
            string result = await WaitSynchronously ();

            // Display the result.
            netcampRss.Text = result;
        */
        }

        void imapClient_NewMessageReceived(object sender, ActiveUp.Net.Mail.NewMessageReceivedEventArgs e)
        {
            
        }

        // The following method runs asynchronously. The UI thread is not
        // blocked during the delay. You can move or resize the Form1 window 
        // while Task.Delay is running.
        public async Task<string> WaitAsynchronouslyAsync()
        {
            await Task.Delay(10000);
            return "Finished";
        }

        // The following method runs synchronously, despite the use of async.
        // You cannot move or resize the Form1 window while Thread.Sleep
        // is running because the UI thread is blocked.
        public async Task<string> WaitSynchronously()
        {
            // Add a using directive for System.Threading.
            Thread.Sleep(10000);
            return "Finished";
        }

        void watek1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            przycisk.Enabled = true;
            MessageBox.Show("tekst1");
            
        }

        void miliard(object objekt, EventArgs e)
        {
            Random random = new Random();
            for (long i = 0; i < 1000000000; i++);           
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }


    }
}
